; Music of Neverending Story (1985) (Ocean Software)
; Ripped by Megachur on 12/11/2006

	write "NEVERENS.BIN"

music_date_rip	equ &0cb6
music_adr	equ &a673
first_theme	equ 0
last_theme	equ 0

	read "music_header_v1_0.asm"

;&a673
	
.la67a equ $ + 7
.la674 equ $ + 1
.la673
	db #8d,#01,#00,#7b,#00,#00,#00,#41
	db #b9,#04,#04,#0a,#1f,#0c,#0a,#16
	db #12,#06,#13,#04,#15,#07,#18,#0e
	db #1c,#0c,#04,#04,#54,#45,#53,#54
	db #46,#49,#4c,#45
.la697
	push af
	ld a,#f5
	in a,(#00)
	rra
	jp c,la6ad
	push bc
	push de
	push hl
	call #9db1
	pop hl
	pop de
	pop bc
	pop af
	ei
	reti
.la6ad
	di
	push bc
	push de
	push hl
	push ix
	ld ix,(la67a)
	ld hl,la750
	ld (ix+#01),l
	ld (ix+#02),h
	ei
	ld hl,#0258
	call la749
	ld b,#7f
	ld c,#9c
	out (c),c
	ld a,#54
	ld c,#00
	out (c),c
	ld c,a
	out (c),c
	ld a,#40
	ld c,#01
	out (c),c
	ld c,a
	out (c),c
	ld a,#4b
	ld c,#02
	out (c),c
	ld c,a
	out (c),c
	ld a,#5e
	ld c,#03
	out (c),c
	ld c,a
	out (c),c
	ld hl,#029d
	call la749
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	nop
	ld c,#8d
	out (c),c
	ld a,#44
	ld c,#00
	out (c),c
	ld c,a
	out (c),c
	ld a,#4a
	ld c,#01
	out (c),c
	ld c,a
	out (c),c
	ld a,#5f
	ld c,#02
	out (c),c
	ld c,a
	out (c),c
	ld a,#4c
	ld c,#03
	out (c),c
	ld c,a
	out (c),c
	ld a,(la674)
	and a
	jp z,la732
	ld c,#89
	out (c),c
.la732
	di
	ld ix,(la67a)
	ld hl,la697
	ld (ix+#01),l
	ld (ix+#02),h
	pop ix
	pop hl
	pop de
	pop bc
	pop af
	ei
	reti
.la749
	dec hl
	ld a,l
	or h
	jp nz,la749
	ret
.la750
	nop
	reti
;
.play_music
.la753
;
	push af
	push bc
	push de
	push hl
	call la768
	defs 3,0	;call #9db1
	call la8da
.la760
	pop hl
	pop de
	pop bc
	pop af
;	reti	; modified by Megachur
	ret
	nop
.la767 equ $ + 1
.la766
	ld b,#06
.la768
	ld a,(la766)
	dec a
	ld (la766),a
	and a
	ret nz
	ld a,(la767)
	ld (la766),a
	pop af
	call la781
	call la8da
	jp la760
.la781
	ld a,(la941)
	or a
	jp m,la793
	ld de,#0000
	ld (la943),de
	ld (la942),de
.la793
	or #80
	ld (la941),a
	and #7f
	add a
	ld l,a
	ld h,#00
	ld de,la7a7
	add hl,de
	ld e,(hl)
	inc hl
	ld d,(hl)
	ex de,hl
	jp (hl)
.la7a7
	dw la7b7,la95c,la992,la9c2
	dw la9f4,laa43,laa7e,laaaa
.la7b7
	xor a
	ld (la94e),a
	ld (la94f),a
	ld (la950),a
	ret
.la7c2
	add hl,bc
	ld a,(hl)
	or a
	ret z
	add a
	ld l,a
	ld h,#00
	cp #02
	jr z,la7d3
	sla e
	ld d,#00
	add hl,de
.la7d3
	ld de,(l6000+&1a)
	add hl,de
	ld e,(hl)
	inc hl
	ld d,(hl)
	ld (la951),de
	ld a,(la94b)
	ld (la948),a
	xor a
	ld (la957),a
	ld (la945),a
	ret
.la7ed
	add hl,bc
	ld a,(hl)
	or a
	ret z
	add a
	ld l,a
	ld h,#00
	cp #02
	jr z,la7fe
	sla e
	ld d,#00
	add hl,de
.la7fe
	ld de,(l6000+&1a)
	add hl,de
	ld e,(hl)
	inc hl
	ld d,(hl)
	ld (la953),de
	ld a,(la94c)
	ld (la949),a
	xor a
	ld (la958),a
	ld (la946),a
	ret
.la818
	add hl,bc
	ld a,(hl)
	or a
	ret z
	add a
	ld l,a
	ld h,#00
	cp #02
	jr z,la829
	sla e
	ld d,#00
	add hl,de
.la829
	ld de,(l6000+&1a)
	add hl,de
	ld e,(hl)
	inc hl
	ld d,(hl)
	ld (la955),de
	ld a,(la94d)
	ld (la94a),a
	xor a
	ld (la959),a
	ld (la947),a
	ret
.la843
	ld (la868),a
	ld a,(la957)
	or a
	jr z,la859
	ld a,(la945)
	inc a
	cp e
	jp nz,la855
	xor a
.la855
	ld (la945),a
	ret nz
.la859
	ld a,#01
	ld (la957),a
	ld a,(la948)
	and a
	ret z
	dec a
	ld (la948),a
.la868 equ $ + 1
	xor #00
	ld (la94e),a
	ret
.la86d
	ld (la892),a
	ld a,(la958)
	or a
	jr z,la883
	ld a,(la946)
	inc a
	cp e
	jp nz,la87f
	xor a
.la87f
	ld (la946),a
	ret nz
.la883
	ld a,#01
	ld (la958),a
	ld a,(la949)
	and a
	ret z
	dec a
	ld (la949),a
.la892 equ $ + 1
	xor #00
	ld (la94f),a
	ret
.la897
	ld (la8bc),a
	ld a,(la959)
	or a
	jr z,la8ad
	ld a,(la947)
	inc a
	cp e
	jp nz,la8a9
	xor a
.la8a9
	ld (la947),a
	ret nz
.la8ad
	ld a,#01
	ld (la959),a
	ld a,(la94a)
	and a
	ret z
	dec a
	ld (la94a),a
.la8bc equ $ + 1
	xor #00
	ld (la950),a
	ret
.la8c1
	ld a,(la942)
	inc a
	cp e
	jp nz,la8cb
	ld a,#00
.la8cb
	ld (la942),a
	ret
.la8cf
	ld hl,(la943)
	inc hl
	ld (la943),hl
	and a
	sbc hl,de
	ret
.la8da
	ld a,(la674)
	and a
	ret nz
	ld hl,(la951)
	ld a,#00
	call la91a
	ld hl,(la953)
	ld a,#02
	call la91a
	ld hl,(la955)
	ld a,#04
	call la91a
	ld a,(la94e)
	ld c,a
	ld a,#08
	call la922
	ld a,(la94f)
	ld c,a
	ld a,#09
	call la922
	ld a,(la950)
	ld c,a
	ld a,#0a
	call la922
	ld a,#07
	ld c,#38
	call la922
	ret
.la91a
	ld c,l
	push af
	call la922
	pop af
	inc a
	ld c,h
.la922
	exx
	ex af,af'
	push af
	push bc
	push de
	push hl
	ld b,#7f
	ld a,(la673)
	ld c,a
	or a
	ex af,af'
	exx
	call lbd34	;#bd34
	exx
	ex af,af'
	ld a,c
	ld (la673),a
	pop hl
	pop de
	pop bc
	pop af
	ex af,af'
	exx
	ret
.la941
	db #00
.la943 equ $ + 1
.la942
	db #00,#00
	db #00
.la945
	db #00
.la946
	db #00
.la947
	db #00
.la948
	db #00
.la949
	db #00
.la94a
	db #00
.la94b
	db #0f
.la94c
	db #0f
.la94d
	db #0f
.la94e
	db #00
.la94f
	db #00
.la951 equ $ + 1
.la950
	db #00,#00
.la953 equ $ + 1
	db #00,#00
.la955 equ $ + 1
	db #00,#00
	db #00
.la957
	db #00
.la958
	db #00
.la959
	db #00
.la95a
	db #00
.la95b
	db #00
.la95c
	call labbc
	xor a
	ld (la95a),a
	ld e,#06
	call la8c1
	jp nz,la991
	ld a,(la943)
	srl a
	srl a
	srl a
	ld (la94b),a
	ld (la94c),a
	ld (la94d),a
	call laaf0
	ld de,#0080
	call la8cf
	jr nz,la991
	ld a,#02
	ld (la941),a
	xor a
	ld (la95b),a
.la991
	ret
.la992
	call labbc
	xor a
	ld (la95a),a
	ld e,#06
	call la8c1
	jp nz,la9c1
	ld a,(la943)
	and #3f
	ld c,a
	ld b,#00
	ld e,#24
	ld hl,(l6000)
	call la818
	call laaf0
	ld de,#0080
	call la8cf
	jr nz,la9c1
	ld a,#03
	ld (la941),a
.la9c1
	ret
.la9c2
	call labbc
	ld e,#06
	call la8c1
	jp nz,la9f3
	ld bc,(la943)
	ld e,#24
	ld hl,(l6000+&02)
	call la818
	call lab34
	ld de,#0080
	call la8cf
	jr nz,la9f3
	ld e,#04
	ld a,(la95b)
	cp #02
	jr nz,la9ef
	ld e,#07
.la9ef
	ld a,e
	ld (la941),a
.la9f3
	ret
.la9f4
	call labbc
	ld e,#06
	call la8c1
	jp nz,laa42
	ld a,(la943)
	and #40
	jr z,laa11
	ld a,(la95b)
	and a
	jr z,laa25
	ld a,#03
	ld (la95a),a
.laa11
	ld a,(la943)
	and #3f
	ld c,a
	ld b,#00
	ld a,(la95a)
	add #24
	ld e,a
	ld hl,(l6000+&04)
	call la818
.laa25
	call laaf0
	ld de,#0080
	call la8cf
	jr nz,laa42
	ld e,#02
	ld a,(la95b)
	and a
	jr z,laa3a
	ld e,#05
.laa3a
	ld a,e
	ld (la941),a
	ld hl,la95b
	inc (hl)
.laa42
	ret
.laa43
	call labbc
	ld e,#07
	ld a,(la943)
	and #80
	jr nz,laa51
	ld e,#04
.laa51
	ld a,e
	ld (la95a),a
	ld e,#06
	call la8c1
	jp nz,laa7d
	ld bc,(la943)
	ld a,(la95a)
	add #24
	ld e,a
	ld hl,(l6000+&06)
	call la818
	call lab78
	ld de,#0100
	call la8cf
	jr nz,laa7d
	ld a,#06
	ld (la941),a
.laa7d
	ret
.laa7e
	call labbc
	ld a,#04
	ld (la95a),a
	ld e,#06
	call la8c1
	jr nz,laaa9
	ld bc,(la943)
	ld e,#24
	ld hl,(l6000+&08)
	call la818
	call lab78
	ld de,#0030
	call la8cf
	jr nz,laaa9
	ld a,#02
	ld (la941),a
.laaa9
	ret
.laaaa
	call labbc
	xor a
	ld (la95a),a
	ld a,(la943)
	srl a
	srl a
	srl a
	srl a
	xor #0f
	ld (la94b),a
	ld (la94c),a
	ld (la94d),a
	ld e,#06
	call la8c1
	jp nz,laaef
	ld a,(la943)
	and #3f
	ld c,a
	ld b,#00
	ld e,#24
	ld hl,(l6000+&04)
	call la818
	call laaf0
	ld de,#0100
	call la8cf
	jr nz,laaef
	ld a,#01
	ld (la941),a
.laaef
	ret
.laaf0
	ld a,(la943)
	and #3f
	srl a
	srl a
	srl a
	ld e,a
	ld d,#00
	ld hl,(l6000+&0a)
	add hl,de
	ld a,(hl)
	ld c,a
	ld a,(la943)
	and #07
	or c
	ld c,a
	ld b,#00
	ld a,(la95a)
	add #24
	ld e,a
	ld hl,(l6000+&10)
	call la7c2
	ld a,(la943)
	and #01
	ret nz
	ld a,(la943)
	and #3f
	srl a
	ld c,a
	ld a,(la95a)
	add #18
	ld e,a
	ld hl,(l6000+&14)
	call la7ed
	ret
.lab34
	ld a,(la943)
	and #3f
	srl a
	srl a
	srl a
	ld e,a
	ld d,#00
	ld hl,(l6000+&0c)
	add hl,de
	ld a,(hl)
	ld c,a
	ld a,(la943)
	and #07
	or c
	ld c,a
	ld b,#00
	ld a,(la95a)
	add #24
	ld e,a
	ld hl,(l6000+&12)
	call la7c2
	ld a,(la943)
	and #01
	ret nz
	ld a,(la943)
	and #3f
	srl a
	ld c,a
	ld a,(la95a)
	add #18
	ld e,a
	ld hl,(l6000+&16)
	call la7ed
	ret
.lab78
	ld a,(la943)
	and #7f
	srl a
	srl a
	srl a
	ld e,a
	ld d,#00
	ld hl,(l6000+&0e)
	add hl,de
	ld a,(hl)
	ld c,a
	ld a,(la943)
	and #07
	or c
	ld c,a
	ld b,#00
	ld a,(la95a)
	add #24
	ld e,a
	ld hl,(l6000+&12)
	call la7c2
	ld a,(la943)
	and #01
	ret nz
	ld a,(la943)
	and #7f
	srl a
	ld c,a
	ld a,(la95a)
	add #18
	ld e,a
	ld hl,(l6000+&18)
	call la7ed
	ret
.labbc
	ld a,#00
	ld e,#01
	call la843
	ld a,#00
	ld e,#01
	call la86d
	ld a,#00
	ld e,#0c
	call la897
	ret
;	nop


.l6000
	dw l601c,l605c,l60dc,l611c
	dw l621c,l624c,l6254,l625c
	dw l626c,l6294,l62b4,l62d4
	dw l62f4,l6334
.l601c
	db #13,#00,#00,#00,#00,#00,#0a,#00
	db #0a,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#0a,#00
	db #0f,#00,#11,#00,#13,#00,#14,#00
	db #16,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#14,#00,#13,#00
	db #14,#00,#13,#00,#11,#00,#13,#00
	db #00,#00,#11,#00,#0f,#00,#00,#00
.l605c
	db #16,#00,#00,#00,#00,#00,#16,#00
	db #16,#00,#00,#00,#00,#00,#19,#00
	db #17,#00,#00,#00,#0d,#00,#00,#00
	db #12,#00,#00,#00,#1b,#00,#00,#00
	db #19,#00,#00,#00,#00,#00,#16,#00
	db #16,#00,#00,#00,#00,#00,#17,#00
	db #14,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #16,#00,#00,#00,#00,#00,#16,#00
	db #16,#00,#00,#00,#00,#00,#19,#00
	db #17,#00,#00,#00,#0d,#00,#00,#00
	db #12,#00,#00,#00,#17,#00,#00,#00
	db #16,#00,#00,#00,#00,#00,#16,#00
	db #16,#00,#00,#00,#00,#00,#17,#00
	db #14,#00,#00,#00,#14,#00,#00,#00
	db #12,#00,#00,#00,#11,#00,#00,#00
.l60dc
	db #0f,#00,#00,#00,#00,#00,#16,#00
	db #16,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#14,#00,#13,#00
	db #14,#00,#13,#00,#11,#00,#13,#00
	db #00,#00,#11,#00,#0f,#00,#11,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
.l611c
	db #12,#00,#00,#00,#00,#00,#19,#00
	db #19,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#19,#19
	db #19,#00,#00,#00,#17,#00,#16,#00
	db #11,#00,#00,#00,#00,#00,#0d,#00
	db #0d,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#0d,#0d
	db #0d,#00,#00,#00,#0f,#00,#11,#00
	db #0f,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#14,#12
	db #11,#00,#00,#00,#11,#00,#00,#00
	db #12,#00,#00,#00,#14,#00,#00,#00
	db #16,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#16,#17
	db #19,#00,#17,#00,#16,#00,#12,#00
	db #00,#00,#0f,#00,#0d,#00,#00,#00
	db #12,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#12,#14
	db #16,#00,#00,#00,#16,#00,#00,#00
	db #14,#00,#00,#00,#12,#00,#00,#00
	db #16,#00,#00,#00,#00,#00,#11,#00
	db #11,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #0f,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#1b,#00
	db #19,#00,#00,#00,#14,#00,#00,#00
	db #16,#00,#00,#00,#17,#00,#00,#00
	db #17,#00,#00,#00,#00,#00,#16,#14
	db #16,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
	db #00,#00,#00,#00,#00,#00,#00,#00
.l621c
	db #26,#24,#22,#1d,#18,#1d,#1a,#16
	db #1a,#18,#16,#11,#16,#11,#0e,#0a
	db #0e,#11,#16,#18,#1a,#1d,#22,#24
	db #26,#24,#22,#1d,#18,#1d,#1a,#16
	db #1a,#18,#16,#11,#16,#11,#0e,#0a
	db #0e,#11,#16,#18,#1a,#1d,#22,#20
.l624c
	db #00,#00,#08,#10,#18,#18,#20,#10
.l6254
	db #00,#00,#00,#00,#08,#08,#10,#10
.l625c
	db #00,#00,#00,#00,#18,#18,#18,#18
	db #08,#08,#10,#10,#00,#00,#00,#00
.l626c
	db #0f,#16,#1b,#16,#0f,#13,#16,#13
	db #0a,#0f,#11,#16,#11,#0f,#0a,#0f
	db #11,#0a,#11,#16,#11,#0a,#0e,#11
	db #0e,#08,#0f,#14,#0f,#08,#0c,#0f
	db #0c,#0c,#0f,#13,#18,#13,#0f,#0c
.l6294
	db #06,#0a,#12,#0a,#06,#0a,#0d,#0a
	db #0b,#12,#16,#12,#0b,#0f,#12,#0f
	db #0d,#14,#19,#14,#0d,#11,#14,#11
	db #0a,#11,#16,#11,#0a,#0d,#11,#0d
.l62b4
	db #0f,#0f,#0f,#0f,#0f,#0f,#0f,#0f
	db #0a,#0a,#0a,#0a,#0a,#0a,#0a,#0a
	db #08,#08,#08,#08,#08,#08,#08,#0a
	db #0c,#0c,#0c,#0c,#0a,#0a,#0a,#0a
.l62d4
	db #06,#06,#06,#06,#06,#06,#06,#06
	db #06,#06,#06,#06,#06,#06,#06,#06
	db #0b,#0b,#0b,#0b,#0b,#0b,#0b,#0b
	db #0d,#0d,#0d,#0d,#0d,#0d,#0d,#0d
.l62f4
	db #06,#06,#06,#06,#06,#06,#06,#06
	db #06,#06,#06,#06,#06,#06,#06,#06
	db #0a,#0a,#0a,#0a,#0a,#0a,#0a,#0a
	db #0a,#0a,#0a,#0a,#0a,#0a,#0a,#0a
	db #0b,#0b,#0b,#0b,#0b,#0b,#0b,#0b
	db #0d,#0d,#0d,#0d,#0d,#0d,#0d,#0d
	db #06,#06,#06,#06,#06,#06,#06,#06
	db #06,#06,#06,#06,#06,#06,#06,#06
.l6334
	db #00,#00,#00,#00,#00,#10,#1a,#0f
	db #41,#0e,#74,#0d,#b3,#0c,#fd,#0b
	db #50,#0b,#ae,#0a,#14,#0a,#83,#09
	db #fb,#08,#7a,#08,#00,#08,#8d,#07
	db #21,#07,#ba,#06,#59,#06,#fe,#05
	db #a8,#05,#57,#05,#0a,#05,#c2,#04
	db #7d,#04,#3d,#04,#00,#04,#c7,#03
	db #90,#03,#5d,#03,#2d,#03,#ff,#02
	db #d4,#02,#ab,#02,#85,#02,#61,#02
	db #3f,#02,#1e,#02,#00,#02,#e3,#01
	db #c8,#01,#af,#01,#96,#01,#80,#01
	db #6a,#01,#56,#01,#43,#01,#30,#01
	db #1f,#01,#0f,#01,#00,#01,#f2,#00
	db #e4,#00,#d7,#00,#cb,#00,#c0,#00
	db #b5,#00,#ab,#00,#a1,#00,#98,#00
	db #90,#00,#88,#00,#80,#00,#79,#00
	db #71,#00,#6c,#00,#66,#00,#60,#00
	db #5b,#00,#55,#00,#51,#00,#4c,#00
	db #48,#00,#44,#00,#40,#00,#00
;-------------------------------------------------------------------------------
.lbd34
;-------------------------------------------------------------------------------
	di
	ld b,#f4
	out (c),a
	ld b,#f6
	in a,(c)
	or #c0
	out (c),a
	and #3f
	out (c),a
	ld b,#f4
	out (c),c
	ld b,#f6
	ld c,a
	or #80
	out (c),a
	out (c),c
	ei
	ret

;
.init_music	; added by Megachur
;
	ld a,#01		;#06
	ld (la941),a
	ld (la766),a
	ld (la767),a
	dec a
	ld (la674),a
	ret
;#9fdd
;ld hl,#a753
;ld ix,(#a67a)
;ld (ix+#00),#c3
;ld (ix+#01),l
;ld (ix+#02),h

;ld a,#00	; init ?
;ld (#a941),a
;ld a,#06
;ld (#a766),a
;ld (#a767),a

;#0863
;add b
;add b
;sub l
;cpl
;ld a,(bc)
;dec b
;rrca
;nop
;ld l,d
;ret nz
;ccf
;rrca
;ld a,(bc)
;dec b
;rrca
;ld a,(bc)
;ccf
;ret nz
;cpl
;rrca
;ld a,(bc)
;
.game_name
	db "Neverending Story",0
.game_year
	db "1985",0
.game_publisher
	db "Ocean Software",0
.music_author
	db "",0
.music_comment
	db "",0

	read "music_end_v1_0.asm"
